// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyNameschemeAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyNameschemeAttributes
//
// Purpose:
//   Information and methods to manage nameschemes
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a NameschemeAttributes.
//
struct NameschemeAttributesObject
{
    PyObject_HEAD
    NameschemeAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewNameschemeAttributes(int);
std::string
PyNameschemeAttributes_ToString(const NameschemeAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    snprintf(tmpStr, 1000, "%snamescheme = \"%s\"\n", prefix, atts->GetNamescheme().c_str());
    str += tmpStr;
    {   const stringVector &externalArrayNames = atts->GetExternalArrayNames();
        snprintf(tmpStr, 1000, "%sexternalArrayNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < externalArrayNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", externalArrayNames[i].c_str());
            str += tmpStr;
            if(i < externalArrayNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &externalArrayOffsets = atts->GetExternalArrayOffsets();
        snprintf(tmpStr, 1000, "%sexternalArrayOffsets = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < externalArrayOffsets.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", externalArrayOffsets[i]);
            str += tmpStr;
            if(i < externalArrayOffsets.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &externalArrayData = atts->GetExternalArrayData();
        snprintf(tmpStr, 1000, "%sexternalArrayData = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < externalArrayData.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", externalArrayData[i]);
            str += tmpStr;
            if(i < externalArrayData.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &allExplicitNames = atts->GetAllExplicitNames();
        snprintf(tmpStr, 1000, "%sallExplicitNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < allExplicitNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", allExplicitNames[i].c_str());
            str += tmpStr;
            if(i < allExplicitNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &explicitIds = atts->GetExplicitIds();
        snprintf(tmpStr, 1000, "%sexplicitIds = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < explicitIds.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", explicitIds[i]);
            str += tmpStr;
            if(i < explicitIds.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &explicitNames = atts->GetExplicitNames();
        snprintf(tmpStr, 1000, "%sexplicitNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < explicitNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", explicitNames[i].c_str());
            str += tmpStr;
            if(i < explicitNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    return str;
}

static PyObject *
NameschemeAttributes_Notify(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_SetNamescheme(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the namescheme in the object.
    obj->data->SetNamescheme(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_GetNamescheme(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetNamescheme().c_str());
    return retval;
}

/*static*/ PyObject *
NameschemeAttributes_SetExternalArrayNames(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetExternalArrayNames() = vec;
    // Mark the externalArrayNames in the object as modified.
    obj->data->SelectExternalArrayNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_GetExternalArrayNames(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the externalArrayNames.
    const stringVector &externalArrayNames = obj->data->GetExternalArrayNames();
    PyObject *retval = PyTuple_New(externalArrayNames.size());
    for(size_t i = 0; i < externalArrayNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(externalArrayNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
NameschemeAttributes_SetExternalArrayOffsets(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetExternalArrayOffsets() = vec;
    // Mark the externalArrayOffsets in the object as modified.
    obj->data->SelectExternalArrayOffsets();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_GetExternalArrayOffsets(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the externalArrayOffsets.
    const intVector &externalArrayOffsets = obj->data->GetExternalArrayOffsets();
    PyObject *retval = PyTuple_New(externalArrayOffsets.size());
    for(size_t i = 0; i < externalArrayOffsets.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(externalArrayOffsets[i])));
    return retval;
}

/*static*/ PyObject *
NameschemeAttributes_SetExternalArrayData(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetExternalArrayData() = vec;
    // Mark the externalArrayData in the object as modified.
    obj->data->SelectExternalArrayData();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_GetExternalArrayData(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the externalArrayData.
    const intVector &externalArrayData = obj->data->GetExternalArrayData();
    PyObject *retval = PyTuple_New(externalArrayData.size());
    for(size_t i = 0; i < externalArrayData.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(externalArrayData[i])));
    return retval;
}

/*static*/ PyObject *
NameschemeAttributes_SetAllExplicitNames(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetAllExplicitNames() = vec;
    // Mark the allExplicitNames in the object as modified.
    obj->data->SelectAllExplicitNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_GetAllExplicitNames(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the allExplicitNames.
    const stringVector &allExplicitNames = obj->data->GetAllExplicitNames();
    PyObject *retval = PyTuple_New(allExplicitNames.size());
    for(size_t i = 0; i < allExplicitNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(allExplicitNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
NameschemeAttributes_SetExplicitIds(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetExplicitIds() = vec;
    // Mark the explicitIds in the object as modified.
    obj->data->SelectExplicitIds();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_GetExplicitIds(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the explicitIds.
    const intVector &explicitIds = obj->data->GetExplicitIds();
    PyObject *retval = PyTuple_New(explicitIds.size());
    for(size_t i = 0; i < explicitIds.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(explicitIds[i])));
    return retval;
}

/*static*/ PyObject *
NameschemeAttributes_SetExplicitNames(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetExplicitNames() = vec;
    // Mark the explicitNames in the object as modified.
    obj->data->SelectExplicitNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
NameschemeAttributes_GetExplicitNames(PyObject *self, PyObject *args)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the explicitNames.
    const stringVector &explicitNames = obj->data->GetExplicitNames();
    PyObject *retval = PyTuple_New(explicitNames.size());
    for(size_t i = 0; i < explicitNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(explicitNames[i].c_str()));
    return retval;
}



PyMethodDef PyNameschemeAttributes_methods[NAMESCHEMEATTRIBUTES_NMETH] = {
    {"Notify", NameschemeAttributes_Notify, METH_VARARGS},
    {"SetNamescheme", NameschemeAttributes_SetNamescheme, METH_VARARGS},
    {"GetNamescheme", NameschemeAttributes_GetNamescheme, METH_VARARGS},
    {"SetExternalArrayNames", NameschemeAttributes_SetExternalArrayNames, METH_VARARGS},
    {"GetExternalArrayNames", NameschemeAttributes_GetExternalArrayNames, METH_VARARGS},
    {"SetExternalArrayOffsets", NameschemeAttributes_SetExternalArrayOffsets, METH_VARARGS},
    {"GetExternalArrayOffsets", NameschemeAttributes_GetExternalArrayOffsets, METH_VARARGS},
    {"SetExternalArrayData", NameschemeAttributes_SetExternalArrayData, METH_VARARGS},
    {"GetExternalArrayData", NameschemeAttributes_GetExternalArrayData, METH_VARARGS},
    {"SetAllExplicitNames", NameschemeAttributes_SetAllExplicitNames, METH_VARARGS},
    {"GetAllExplicitNames", NameschemeAttributes_GetAllExplicitNames, METH_VARARGS},
    {"SetExplicitIds", NameschemeAttributes_SetExplicitIds, METH_VARARGS},
    {"GetExplicitIds", NameschemeAttributes_GetExplicitIds, METH_VARARGS},
    {"SetExplicitNames", NameschemeAttributes_SetExplicitNames, METH_VARARGS},
    {"GetExplicitNames", NameschemeAttributes_GetExplicitNames, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
NameschemeAttributes_dealloc(PyObject *v)
{
   NameschemeAttributesObject *obj = (NameschemeAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *NameschemeAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyNameschemeAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "namescheme") == 0)
        return NameschemeAttributes_GetNamescheme(self, NULL);
    if(strcmp(name, "externalArrayNames") == 0)
        return NameschemeAttributes_GetExternalArrayNames(self, NULL);
    if(strcmp(name, "externalArrayOffsets") == 0)
        return NameschemeAttributes_GetExternalArrayOffsets(self, NULL);
    if(strcmp(name, "externalArrayData") == 0)
        return NameschemeAttributes_GetExternalArrayData(self, NULL);
    if(strcmp(name, "allExplicitNames") == 0)
        return NameschemeAttributes_GetAllExplicitNames(self, NULL);
    if(strcmp(name, "explicitIds") == 0)
        return NameschemeAttributes_GetExplicitIds(self, NULL);
    if(strcmp(name, "explicitNames") == 0)
        return NameschemeAttributes_GetExplicitNames(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyNameschemeAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyNameschemeAttributes_methods[i].ml_name),
                PyString_FromString(PyNameschemeAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyNameschemeAttributes_methods, self, name);
}

int
PyNameschemeAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "namescheme") == 0)
        obj = NameschemeAttributes_SetNamescheme(self, args);
    else if(strcmp(name, "externalArrayNames") == 0)
        obj = NameschemeAttributes_SetExternalArrayNames(self, args);
    else if(strcmp(name, "externalArrayOffsets") == 0)
        obj = NameschemeAttributes_SetExternalArrayOffsets(self, args);
    else if(strcmp(name, "externalArrayData") == 0)
        obj = NameschemeAttributes_SetExternalArrayData(self, args);
    else if(strcmp(name, "allExplicitNames") == 0)
        obj = NameschemeAttributes_SetAllExplicitNames(self, args);
    else if(strcmp(name, "explicitIds") == 0)
        obj = NameschemeAttributes_SetExplicitIds(self, args);
    else if(strcmp(name, "explicitNames") == 0)
        obj = NameschemeAttributes_SetExplicitNames(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
NameschemeAttributes_print(PyObject *v, FILE *fp, int flags)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)v;
    fprintf(fp, "%s", PyNameschemeAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
NameschemeAttributes_str(PyObject *v)
{
    NameschemeAttributesObject *obj = (NameschemeAttributesObject *)v;
    return PyString_FromString(PyNameschemeAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *NameschemeAttributes_Purpose = "Information and methods to manage nameschemes";
#else
static char *NameschemeAttributes_Purpose = "Information and methods to manage nameschemes";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(NameschemeAttributesType,         \
                  "NameschemeAttributes",           \
                  NameschemeAttributesObject,       \
                  NameschemeAttributes_dealloc,     \
                  NameschemeAttributes_print,       \
                  PyNameschemeAttributes_getattr,   \
                  PyNameschemeAttributes_setattr,   \
                  NameschemeAttributes_str,         \
                  NameschemeAttributes_Purpose,     \
                  NameschemeAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
NameschemeAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &NameschemeAttributesType
         || Py_TYPE(other) != &NameschemeAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    NameschemeAttributes *a = ((NameschemeAttributesObject *)self)->data;
    NameschemeAttributes *b = ((NameschemeAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static NameschemeAttributes *defaultAtts = 0;
static NameschemeAttributes *currentAtts = 0;

static PyObject *
NewNameschemeAttributes(int useCurrent)
{
    NameschemeAttributesObject *newObject;
    newObject = PyObject_NEW(NameschemeAttributesObject, &NameschemeAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new NameschemeAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new NameschemeAttributes(*defaultAtts);
    else
        newObject->data = new NameschemeAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapNameschemeAttributes(const NameschemeAttributes *attr)
{
    NameschemeAttributesObject *newObject;
    newObject = PyObject_NEW(NameschemeAttributesObject, &NameschemeAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (NameschemeAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
NameschemeAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewNameschemeAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef NameschemeAttributesMethods[] = {
    {"NameschemeAttributes", NameschemeAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *NameschemeAttributesObserver = 0;

std::string
PyNameschemeAttributes_GetLogString()
{
    std::string s("NameschemeAtts = NameschemeAttributes()\n");
    if(currentAtts != 0)
        s += PyNameschemeAttributes_ToString(currentAtts, "NameschemeAtts.", true);
    return s;
}

static void
PyNameschemeAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("NameschemeAtts = NameschemeAttributes()\n");
        s += PyNameschemeAttributes_ToString(currentAtts, "NameschemeAtts.", true);
        cb(s);
    }
}

void
PyNameschemeAttributes_StartUp(NameschemeAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyNameschemeAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(NameschemeAttributesObserver == 0)
    {
        NameschemeAttributesObserver = new ObserverToCallback(subj,
            PyNameschemeAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyNameschemeAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete NameschemeAttributesObserver;
    NameschemeAttributesObserver = 0;
}

PyMethodDef *
PyNameschemeAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return NameschemeAttributesMethods;
}

bool
PyNameschemeAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &NameschemeAttributesType);
}

NameschemeAttributes *
PyNameschemeAttributes_FromPyObject(PyObject *obj)
{
    NameschemeAttributesObject *obj2 = (NameschemeAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyNameschemeAttributes_New()
{
    return NewNameschemeAttributes(0);
}

PyObject *
PyNameschemeAttributes_Wrap(const NameschemeAttributes *attr)
{
    return WrapNameschemeAttributes(attr);
}

void
PyNameschemeAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    NameschemeAttributesObject *obj2 = (NameschemeAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyNameschemeAttributes_SetDefaults(const NameschemeAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new NameschemeAttributes(*atts);
}

